package com.upeoe.shiro.chapter2;

import org.junit.Assert;
import org.junit.Test;

/**
 * @author ven_hxz
 * @create 2016-07-03 下午2:09
 */
public class AuthorizerTutorial extends LoginHelper {
    @Test
    public void testIsPermittedByConfigFile() {
        login("classpath:shiro-authorizer.ini", "root", "root");

        Assert.assertTrue(getSubject().isPermitted("user1:update"));
        Assert.assertTrue(getSubject().isPermitted("user2:update"));

        Assert.assertTrue(getSubject().isPermitted("+user1+2"));
        Assert.assertTrue(getSubject().isPermitted("+user1+8"));
        Assert.assertTrue(getSubject().isPermitted("+user2+10"));

        Assert.assertFalse(getSubject().isPermitted("+user1+4"));
    }

    @Test
    public void testIsPermittedByDataBase() {
        login("classpath:shiro-jdbc-authorizer.ini", "root", "root");

        Assert.assertTrue(getSubject().isPermitted("user1:update"));
        Assert.assertTrue(getSubject().isPermitted("user2:update"));

        Assert.assertTrue(getSubject().isPermitted("+user1+2"));
        Assert.assertTrue(getSubject().isPermitted("+user1+8"));
        Assert.assertTrue(getSubject().isPermitted("+user1+10"));

        Assert.assertFalse(getSubject().isPermitted("+user1+4"));
        //Assert.assertTrue(getSubject().isPermitted("menu:view"));

    }
}
